package com.veryUsedCar.controller;

import com.veryUsedCar.VO.NewsVO;
import com.veryUsedCar.data.Result;
import com.veryUsedCar.service.NewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/msg/v1")
@Slf4j
@Api(value = "消息接口")
@RefreshScope //刷新配置
public class NewsController {
    @Autowired
    private NewsService newsService;

    @PostMapping
    @ApiOperation("增加消息")
    @ApiImplicitParam(name = "news",value = "增加消息",required = true, paramType = "body")
    public Result saveNews(NewsVO news){
        newsService.saveNews(news);
        return Result.OK();
    }

    @GetMapping
    @ApiOperation("查询消息")
    @ApiImplicitParam(name = "null",value = "查询消息",required = false, paramType = "null")
    public Result listNews(){
        newsService.listNews();
        return Result.OK();
    }

    @DeleteMapping
    @ApiOperation("删除消息")
    @ApiImplicitParam(name = "newsId",value = "删除消息",required = true, paramType = "body")
    public Result deleteNews(@RequestParam Long newsId){
        newsService.deleteNews(newsId);
        return Result.OK();
    }

}
